<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentFriendsAdd.class.php, $Author:  $ */



/** Add friend compnent
 *
 * Parameters:
 *  1. oUser (mandatory) - user account object (who wants to add)
 *  2. oAddUser (mandatory) - user to add (whom want to add)
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentFriendsAdd.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentFriendsAdd extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oCurrUser = $this->getParam('oUser');
	    assert(null != $oCurrUser);
	    $oAddUser = $this->getParam('oAddUser');
	    assert(null != $oAddUser);

	    //check for blocking
        $oSrvBlock = App::getModuleService('Account', 'Block');
        /* @var $oSrvBlock PhpFox_Mod_Account_ServiceBlock */
        $bIsBlocked = $oSrvBlock->isBlocked($oAddUser, $oCurrUser);

	    $oSrvFriends = $this->_oModule->getService('Friends');
	    /* @var $oSrvFriends PhpFox_Mod_Account_ServiceFriends */
	    $bIsFriend = $oSrvFriends->isFriend($oAddUser, $oCurrUser);
	    $bIsFriendRequest = !$bIsFriend && $oSrvFriends->isFriendReqest($oAddUser, $oCurrUser);

        if (!$bIsFriend && !$bIsFriendRequest)
        {
            //add friend request
            $oSrvFriends->addFriendRequest($oAddUser, $oCurrUser);
        }


        $oTpl = &$this->_oModule->getTemplate();

        $oTpl->assign(array(
            'bIsBlocked'       => $bIsBlocked,
            'bIsFriend'        => $bIsFriend,
            'bIsFriendRequest' => $bIsFriendRequest,
            'aCurrUser'        => $oCurrUser->aData,
            'aAddUser'         => $oAddUser->aData,
        ));

		$srcHtml = $oTpl->fetch('FriendsAdd.html');
		return $srcHtml;
	}

}
?>